package com.c.opt.enums;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.EnumUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import ntd.util.config.common.enums.BaseEnumInterface;

/**
 * 数据查询规则类型
 */
@AllArgsConstructor
public enum EnumQueryRuleType implements BaseEnumInterface {

    RULE_EQ("eq", "="),
    RULE_NE("ne", "<>"),
    RULE_LIKE("like", "LIKE"),
    RULE_NOT_LIKE("not_like", "NOT LIKE"),
    RULE_GE("ge", ">="),
    RULE_GT("gt", ">"),
    RULE_LE("le", "<="),
    RULE_LT("lt", "<"),
    RULE_IN("in", "IN"),
    RULE_NOT_IN("not_in", "NOT IN"),
    RULE_IS_NULL("null", "IS NULL"),
    RULE_IS_NOT_NULL("not_null", "IS NOT NULL"),
    RULE_BETWEEN("between", "BETWEEN"),
    RULE_NOT_BETWEEN("not_between", "NOT BETWEEN"),
    ;

    @Getter
    private String name;

    @Getter
    private String content;

    @Override
    public String getValue() {
        return this.getName();
    }

    public static EnumQueryRuleType val(String name) {
        return EnumUtil.getBy(EnumQueryRuleType.class, enumQueryRuleType -> enumQueryRuleType.getName().equals(name));
    }

    /**
     * 是否是noVal类型
     * @return
     */
    public boolean isNoVal() {
        return ListUtil.of(RULE_IS_NULL, RULE_IS_NOT_NULL).contains(this);
    }

}
